package zhuzx.encaps;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.DispatcherServlet;

public class DynamicDispatcherServlet extends DispatcherServlet {
	
	private static final long serialVersionUID = -7300541165368503334L;

	public void reload() {
		/* 
		 * configureAndRefreshWebApplicationContext可行，（也许）可重新定位配置信息。
		 * initWebApplicationContext需要检测wac状态，wac无公共修改器。
		 * onRefresh无效。
		 */
		System.out.println(">>>>>>>>>>adding>>>>>>>>>>>");
		super.refresh();
		System.out.println(">>>>>>>>>>added>>>>>>>>>>>");
	}
	
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path = request.getServletPath();
		String actionName = super.getServletConfig().getInitParameter("actionNameOfAddController");
		if (path.equals(actionName)) {
			reload();
		} else {
			super.service(request, response);
		}
	}
	
}